package com.woniuxy.tools.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.woniuxy.entity.AllShop;
import com.woniuxy.service.ShopService;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author hq
 * @Date 2025/7/22$ 15:43$
 * @Description TODO
 * @Params $
 * @Return $
 **/
@Service
public class ShopToolService {
    @Autowired
    private ShopService shopService;
    @Tool(description = "搜索闲置商品")
    public String searchProducts(String keyword) {
        List<AllShop> products = shopService.search(keyword);
        ObjectMapper mapper = new ObjectMapper();
        String json = null;
        try {
            json = mapper.writeValueAsString(products);
        }catch (Exception e){
            return "没有找到商品";
        }
        return json;
    }
    @Tool(description = "获取商品详情")
    public String getProductDetails(Integer shopId) {
        AllShop product = shopService.getById(shopId);
        ObjectMapper mapper = new ObjectMapper();
        String json = null;
        try {
            json = mapper.writeValueAsString(product);
        }catch (Exception e){
            return "没有找到商品";
        }
        return json;
    }
    @Tool(description = "查询价格区间商品")
    public String getProductsByPriceRange(Integer minPrice, Integer maxPrice) {
        List<AllShop> products = shopService.getProductsByPriceRange(minPrice, maxPrice);
        ObjectMapper mapper = new ObjectMapper();
        String json = null;
        try {
            json = mapper.writeValueAsString(products);
        }catch (Exception e){
            return "没有找到商品";
        }
        return json;
    }
}
